// Copyright (c) 2024-present AI-Labs

// @ ts-nocheck
import { AppPlugin } from "@/plugins/AppPlugin.ts";

/**
 * 插件注册器
 */
export class AppPluginRegistry {
    private static instance: AppPluginRegistry;
    private plugins: AppPlugin[] = [];

    private constructor() { }

    /**
     * 获取单例实例
     */
    public static getInstance(): AppPluginRegistry {
        if (!AppPluginRegistry.instance) {
            AppPluginRegistry.instance = new AppPluginRegistry();
        }
        return AppPluginRegistry.instance;
    }

    /**
     * 注册容器插件
     * @param plugin 容器插件
     */
    public registerPlugin(plugin: AppPlugin): void {
        this.plugins.push(plugin);
    }

    /**
     * 获取所有注册的容器插件
     */
    public getPlugins(): AppPlugin[] {
        return this.plugins;
    }

    /**
     * 根据名称获取插件
     * @param name 插件名称
     */
    public getPluginByName(name: string): AppPlugin | undefined {
        return this.plugins.find(plugin => plugin.getName() === name);
    }
}